package com.canbot.u05.activity.customvoice.tool

import java.util.*
import java.util.regex.Pattern

/**
 * @author Liu.Heng
 * Created by cool on 2018/6/6.
 */

object CheckStringUtils {

    /**
     * 验证字符串是只包含中文or英文
     *
     * @param string 检测的字符串
     * @return 返回结果
     */
    fun isChineseOrEnglish(string: String): Boolean {
        val chinese = "^[\u4e00-\u9fa5]+$"
        val english = "^[A-Za-z\\s-]+$"
        val language = Locale.getDefault().language

        val matchesStr = if (language.contains("zh")) {
            chinese
        } else {
            english
        }
        return Pattern.matches(matchesStr, string)
    }

}
